//
//  LGTMessageCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/9/3.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTMessageCell: UITableViewCell {

    private var _model:Dictionary<String, Any>?
    var appNameLabel:UILabel?
    var titleLabel:UILabel?
    var contentLabel:UILabel?
    var timeLabel:UILabel?
    var model:Dictionary<String, Any>?{
        get{
            return _model
        }set{
            _model = newValue
            self.setData()
        }
    }
    
    func setData(){
        self.appNameLabel?.text = AppName
        let type:Int = self.model?["type"] as? Int ?? 0
        if type == 1{
            self.appNameLabel?.text = "系统公告"
        }
        self.timeLabel?.text = self.model?["publish_time"] as? String ?? ""
        self.titleLabel?.text = self.model?["title"] as? String ?? ""
        self.contentLabel?.text = self.model?["content"] as? String ?? ""
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        let appicon:UIImageView = LGTViewCreateUtil.share.createImageView(image: "zhu_icon2")
        self.addSubview(appicon)
        appicon.snp.makeConstraints { (make) in
            make.width.height.equalTo(SizeFit(25))
            make.left.equalTo(SizeFit(13))
            make.top.equalTo(SizeFit(24))
        }
        
        self.appNameLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: GrayColor, fontSize: SizeFitFloat(12))
        self.addSubview(self.appNameLabel!)
        self.appNameLabel!.snp.makeConstraints { (make) in
            make.centerY.equalTo(appicon)
            make.height.equalTo(SizeFitFloat(12))
            make.left.equalTo(SizeFitFloat(47))
        }
        
        self.timeLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: GrayColor, fontSize: SizeFitFloat(12))
        self.addSubview(self.timeLabel!)
        self.timeLabel!.snp.makeConstraints { (make) in
            make.centerY.equalTo(appicon)
            make.height.equalTo(SizeFitFloat(12))
            make.right.equalTo(-SizeFitFloat(11))
        }
        
        self.titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(12))
        self.titleLabel?.font = KBFont(size: SizeFitFloat(15))
        self.addSubview(self.titleLabel!)
        self.titleLabel!.snp.makeConstraints { (make) in
            make.top.equalTo(appicon.snp_bottomMargin).offset(SizeFit(14))
            make.right.equalTo(SizeFitFloat(-11))
            make.left.equalTo(SizeFitFloat(47))
        }
        
        self.contentLabel =  LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(15))
        self.addSubview(self.contentLabel!)
        self.contentLabel!.snp.makeConstraints { (make) in
            make.top.equalTo(self.titleLabel!.snp_bottomMargin).offset(SizeFit(12))
            make.right.equalTo(SizeFitFloat(-11))
            make.left.equalTo(SizeFitFloat(47))
        }
        
        let button = LGTViewCreateUtil.share.createTextLGTButton(title: "查看详情>>", font: Font_Normal_15, color: ColorUtil(color: 0x488DFF), selectedColor: ColorUtil(color: 0x488DFF), dW: SizeFitFloat(5), dH: SizeFitFloat(5))
        self.addSubview(button)
        button.isUserInteractionEnabled = false
        button.snp.makeConstraints { (make) in
            make.right.equalTo(-SizeFitFloat(12))
            make.width.equalTo(SizeFitFloat(80))
            make.height.equalTo(16)
            make.top.equalTo(self.contentLabel!.snp_bottomMargin).offset(SizeFitFloat(10))
        }
        
        let line:UIImageView = LGTViewCreateUtil.share.createLineView()
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFitFloat(13))
            make.right.equalTo(-SizeFitFloat(10))
            make.height.equalTo(1)
            make.bottom.equalTo(0)
            make.top.equalTo(button.snp_bottomMargin).offset(SizeFit(30))
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
